<!DOCTYPE html>
<html>
  
<head>
  <meta charset="utf-8">
  <meta name="author" content="饿包子" />
  
  
  <title>功能与样式的参考和沉淀代码 | 饿包子博客</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="Javascript," />
  

  
  <meta name="description" content="陈年老代码，它会非常繁琐枯燥。">

  
  
    <link rel="icon" href="/blog/images/xian.ico">
    <link rel="apple-touch-icon" href="/blog/images/Logo.png">
  

  
<link rel="stylesheet" href="/blog/css/Awesome.min.css">


  
<link rel="stylesheet" href="/blog/css/index.css">
<link rel="stylesheet" href="/blog/styles/components/highlight/highlight.css">


  
  
<script src="/blog/common/jquery.min.js"></script>

  
    
<script src="/blog/common/Av.min.js"></script>

  

  
    
<script src="/blog/common/MathJax.js"></script>

  

  
    
<script src="/blog/common/Valine.min.js"></script>

  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"gE1EosDsVgB2slV4E92yPkcG-gzGzoHsz","appkey":"niR787UVTMyJQrR6gmOiJCKe","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2018-06-10",
    passwords: ["a621ab606db2a11f63edc576a729843b8269250dc324206871d90635ac5e531c", ],
    is_post: true,
    lock: false,
    author: "饿包子",
    share: {"twitter":false,"facebook":false,"weibo":true,"qq":true,"wechat":false},
    mathjax: true,
    page_type: "",
    root: "/blog/"
  };
</script>

  
<script src="/blog/vendor/sha256.min.js"></script>
<script src="/blog/js/auth.js"></script>
<script src="/blog/js/index.js"></script>
<script src="/blog/vendor/qrcode.min.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/blog/">清风逐月</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 我思故我在</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/blog/" target="_self">主页</a>
      
        <a href="/blog/archives/" target="_self">归档</a>
      
        <a href="/blog/tags/" target="_self">标签</a>
      
        <a href="/blog/categories/" target="_self">分类</a>
      
        <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">日记</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/lixianbin1/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/blog/" target="_self">
            主页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">
            日记
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2022-02-11
    </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
    <span>
       | <i class="fa fa-calendar"></i>更新时间:2022-2-11 11:3 
    </span>
  </div>
  <h1 class="passage-title">
    功能与样式的参考和沉淀代码
  </h1>
  
  <article class="passage-article">
    <h3 id="页面打印及4A大小的设置"><a href="#页面打印及4A大小的设置" class="headerlink" title="页面打印及4A大小的设置"></a>页面打印及4A大小的设置</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> dom=<span class="string">&quot;&lt;!DOCTYPE html&gt;...&lt;/html&gt;&quot;</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">doPrint3</span>(<span class="params">dom</span>)&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//判断iframe是否存在，不存在则创建iframe</span></span><br><span class="line">    <span class="keyword">var</span> iframe=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;print-iframe&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(!iframe)&#123;  </span><br><span class="line">        <span class="keyword">var</span> el = <span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;printcontent&quot;</span>);</span><br><span class="line">        iframe = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&#x27;IFRAME&#x27;</span>);</span><br><span class="line">        iframe.<span class="title function_">setAttribute</span>(<span class="string">&quot;id&quot;</span>, <span class="string">&quot;print-iframe&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 需要预览就添加大小。A4的内容大小。不需要就隐藏</span></span><br><span class="line">        iframe.<span class="title function_">setAttribute</span>(<span class="string">&#x27;style&#x27;</span>, <span class="string">&#x27;width:794px;height:1090px;&#x27;</span>); </span><br><span class="line">        <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(iframe);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 如果传入dom，则打印dom</span></span><br><span class="line">        iframe.<span class="property">contentWindow</span>.<span class="property">document</span>.<span class="property">documentElement</span>.<span class="property">innerHTML</span>=dom</span><br><span class="line">        <span class="keyword">var</span> doc = iframe.<span class="property">contentWindow</span>.<span class="property">document</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//这里可以自定义打印样式</span></span><br><span class="line">        doc.<span class="title function_">write</span>(<span class="string">&quot;&lt;LINK rel=&quot;</span>stylesheet<span class="string">&quot; type=&quot;</span>text/css<span class="string">&quot; href=&quot;</span>css/print.<span class="property">css</span><span class="string">&quot;&gt;&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//如果不传dom 需要单独打印部分内容</span></span><br><span class="line">        <span class="comment">//doc.write(&#x27;&lt;div&gt;&#x27; + el.innerHTML + &#x27;&lt;/div&gt;&#x27;);</span></span><br><span class="line">        <span class="comment">//doc.close();</span></span><br><span class="line">        <span class="comment">//iframe.contentWindow.focus();            </span></span><br><span class="line">    &#125;</span><br><span class="line">    iframe.<span class="property">contentWindow</span>.<span class="title function_">print</span>();</span><br><span class="line">    <span class="keyword">if</span> (navigator.<span class="property">userAgent</span>.<span class="title function_">indexOf</span>(<span class="string">&quot;MSIE&quot;</span>) &gt; <span class="number">0</span>)&#123; <span class="comment">// IE浏览器</span></span><br><span class="line">      <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(iframe);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 打印</span></span><br><span class="line"><span class="title function_">doPrint3</span>(<span class="params">dom</span>)&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//判断iframe是否存在，不存在则创建iframe</span></span><br><span class="line">    <span class="keyword">var</span> iframe=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;print-iframe&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(!iframe)&#123;</span><br><span class="line">      iframe = <span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&#x27;IFRAME&#x27;</span>);</span><br><span class="line">      iframe.<span class="title function_">setAttribute</span>(<span class="string">&quot;id&quot;</span>, <span class="string">&quot;print-iframe&quot;</span>);</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 需要预览就添加大小。A4的内容大小。不需要就隐藏</span></span><br><span class="line">      iframe.<span class="title function_">setAttribute</span>(<span class="string">&#x27;style&#x27;</span>, <span class="string">&#x27;width:794px;height:1090px;&#x27;</span>); </span><br><span class="line">      <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">appendChild</span>(iframe);</span><br><span class="line">      iframe.<span class="property">contentWindow</span>.<span class="property">document</span>.<span class="property">documentElement</span>.<span class="property">innerHTML</span>=dom  </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">      iframe.<span class="property">contentWindow</span>.<span class="title function_">print</span>();</span><br><span class="line">      <span class="keyword">var</span> doc = iframe.<span class="property">contentWindow</span>.<span class="property">document</span>;</span><br><span class="line">      doc.<span class="title function_">close</span>();</span><br><span class="line">      iframe.<span class="property">contentWindow</span>.<span class="title function_">focus</span>(); </span><br><span class="line">      <span class="variable language_">document</span>.<span class="property">body</span>.<span class="title function_">removeChild</span>(iframe);</span><br><span class="line">    &#125;,<span class="number">10</span>)</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>


<h3 id="手机和电脑长按的混合处理"><a href="#手机和电脑长按的混合处理" class="headerlink" title="手机和电脑长按的混合处理"></a>手机和电脑长按的混合处理</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> isAndroid=<span class="regexp">/Android|webOS|iPhone|ipod|ipad|BlackBerry/i</span>.<span class="title function_">test</span>(navigator.<span class="property">userAgent</span>)</span><br><span class="line"><span class="keyword">let</span> set1,set2,isLong=<span class="number">0</span>,start=<span class="literal">false</span></span><br><span class="line"><span class="keyword">let</span> dom=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&#x27;aaa&#x27;</span>)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;touchstart&#x27;</span>,a)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;touchmove&#x27;</span>,b)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;touchend&#x27;</span>,c)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;mousedown&#x27;</span>,a)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>,b)</span><br><span class="line">  dom.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;mouseup&#x27;</span>,c)</span><br><span class="line"><span class="keyword">if</span>(isAndroid)&#123;</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;touchstart&#x27;</span>,a)</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;touchmove&#x27;</span>,b)</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;touchend&#x27;</span>,c) </span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mousedown&#x27;</span>,a)</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>,b)</span><br><span class="line">  dom.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mouseup&#x27;</span>,c)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">a</span>(<span class="params"></span>)&#123;</span><br><span class="line">  <span class="comment">//多次触发</span></span><br><span class="line">  start=<span class="literal">true</span></span><br><span class="line">  set1=<span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;这次是长按&#x27;</span>)</span><br><span class="line">    isLong=<span class="number">1</span></span><br><span class="line">  &#125;,<span class="number">800</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">b</span>(<span class="params"></span>)&#123;</span><br><span class="line">  <span class="comment">//移动</span></span><br><span class="line">  <span class="keyword">if</span>(start)&#123;</span><br><span class="line">    isLong=<span class="number">2</span></span><br><span class="line">    <span class="built_in">clearTimeout</span>(set1)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">c</span>(<span class="params"></span>)&#123;</span><br><span class="line">  <span class="comment">//离开</span></span><br><span class="line">  <span class="keyword">if</span>(isLong==<span class="number">0</span>)&#123;</span><br><span class="line">    <span class="built_in">clearTimeout</span>(set1)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;这次是单击&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  isLong=<span class="number">0</span></span><br><span class="line">  start=<span class="literal">false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h3 id="数据表格和固定头部的样式"><a href="#数据表格和固定头部的样式" class="headerlink" title="数据表格和固定头部的样式"></a>数据表格和固定头部的样式</h3><figure class="highlight js"><figcaption><span>React 代码</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> * <span class="keyword">as</span> <span class="title class_">React</span> <span class="keyword">from</span> <span class="string">&#x27;react&#x27;</span></span><br><span class="line"><span class="keyword">var</span> $ = <span class="built_in">require</span>(<span class="string">&#x27;jquery&#x27;</span>)</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">class</span> <span class="title class_">LTable</span> <span class="keyword">extends</span> <span class="title class_ inherited__">React.Component</span>&lt;any,any&gt;&#123;</span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params">props:any</span>) &#123;</span><br><span class="line">    <span class="variable language_">super</span>(props);</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">resize</span>=<span class="variable language_">this</span>.<span class="property">resize</span>.<span class="title function_">bind</span>(<span class="variable language_">this</span>)</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">state</span> = &#123;</span><br><span class="line">      <span class="attr">id</span>:<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">id</span>||<span class="string">&#x27;l_&#x27;</span>+<span class="keyword">new</span> <span class="title class_">Date</span>().<span class="title function_">getTime</span>(),</span><br><span class="line">      <span class="attr">clas</span>:<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">className</span>||<span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      <span class="attr">height</span>:<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">height</span>||<span class="string">&#x27;300px&#x27;</span>,</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">static</span> contextTypes=&#123;  </span><br><span class="line">    <span class="attr">router</span>: <span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="literal">null</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  mounted = <span class="literal">false</span>;</span><br><span class="line">  <span class="title function_">componentWillMount</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">mounted</span> = <span class="literal">true</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">componentDidMount</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;resize&#x27;</span>, <span class="variable language_">this</span>.<span class="property">resize</span>)</span><br><span class="line">    <span class="variable language_">this</span>.<span class="title function_">resize</span>()</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">componentDidUpdate</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="title function_">resize</span>()</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">componentWillUnmount</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">window</span>.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;resize&#x27;</span>,<span class="variable language_">this</span>.<span class="property">resize</span>);</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">mounted</span> = <span class="literal">false</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">resize</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">let</span> id=<span class="variable language_">this</span>.<span class="property">state</span>.<span class="property">id</span></span><br><span class="line">    <span class="keyword">let</span> tbody=<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">tbody</span></span><br><span class="line">    <span class="keyword">if</span>(tbody.<span class="property">length</span>&gt;<span class="number">0</span>)&#123;</span><br><span class="line">      <span class="keyword">let</span> ltable=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(id)!.<span class="title function_">getElementsByTagName</span>(<span class="string">&#x27;table&#x27;</span>)</span><br><span class="line">      <span class="keyword">let</span> thead0=ltable[<span class="number">0</span>].<span class="title function_">getElementsByTagName</span>(<span class="string">&#x27;thead&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">      <span class="keyword">let</span> thead1=ltable[<span class="number">1</span>].<span class="title function_">getElementsByTagName</span>(<span class="string">&#x27;thead&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">      <span class="keyword">let</span> ltbody=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(id)!.<span class="title function_">getElementsByClassName</span>(<span class="string">&#x27;l_table_body&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">      <span class="keyword">let</span> th0=thead0.<span class="title function_">getElementsByTagName</span>(<span class="string">&#x27;th&#x27;</span>)</span><br><span class="line">      <span class="keyword">let</span> th1=thead1.<span class="title function_">getElementsByTagName</span>(<span class="string">&#x27;th&#x27;</span>)</span><br><span class="line">      thead0.<span class="property">style</span>.<span class="property">minWidth</span>=thead1.<span class="property">offsetWidth</span>+<span class="string">&#x27;px&#x27;</span></span><br><span class="line">      ltable[<span class="number">0</span>].<span class="property">style</span>.<span class="property">width</span>=ltable[<span class="number">1</span>].<span class="property">offsetWidth</span>+<span class="string">&#x27;px&#x27;</span></span><br><span class="line">      <span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span>;i&lt;th1.<span class="property">length</span>;i++)&#123;</span><br><span class="line">        th0[i].<span class="property">style</span>.<span class="property">width</span>=th1[i].<span class="property">offsetWidth</span>+<span class="string">&#x27;px&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">      $(ltbody).<span class="title function_">scroll</span>(<span class="keyword">function</span>(<span class="params">e:any</span>)&#123;</span><br><span class="line">        <span class="keyword">let</span> div=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(id)!.<span class="title function_">getElementsByClassName</span>(<span class="string">&#x27;l_table_head&#x27;</span>)[<span class="number">0</span>]</span><br><span class="line">        div.<span class="property">scrollLeft</span>=e.<span class="property">target</span>.<span class="property">scrollLeft</span></span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">render</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">let</span> thead=<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">thead</span>,tbody=<span class="variable language_">this</span>.<span class="property">props</span>.<span class="property">tbody</span></span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">    <span class="language-xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&#123;this.state.id&#125;</span> <span class="attr">className</span>=<span class="string">&#123;</span>&quot;<span class="attr">l_table</span> &quot;+<span class="attr">this.state.clas</span>&#125;&gt;</span></span></span><br><span class="line"><span class="language-xml">      &#123;this.props.title?</span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">h3</span> <span class="attr">className</span>=<span class="string">&quot;l_table_title&quot;</span>&gt;</span>&#123;this.props.title&#125;<span class="tag">&lt;/<span class="name">h3</span>&gt;</span>:&#x27;&#x27;</span></span><br><span class="line"><span class="language-xml">      &#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">className</span>=<span class="string">&quot;l_table_head l_scroll_hide&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">table</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;<span class="name">thead</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            <span class="tag">&lt;<span class="name">tr</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            &#123;thead.map((e:any,i:any)=&gt;</span></span><br><span class="line"><span class="language-xml">              <span class="tag">&lt;<span class="name">th</span> <span class="attr">key</span>=<span class="string">&#123;i&#125;</span>&gt;</span>&#123;e.title&#125;<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            )&#125;</span></span><br><span class="line"><span class="language-xml">            <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;/<span class="name">thead</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;/<span class="name">table</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">className</span>=<span class="string">&quot;l_table_body&quot;</span> <span class="attr">style</span>=<span class="string">&#123;&#123;height:this.state.height&#125;&#125;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        &#123;tbody.length&gt;0?</span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">table</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;<span class="name">thead</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            <span class="tag">&lt;<span class="name">tr</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            &#123;thead.map((e:any,i:any)=&gt;</span></span><br><span class="line"><span class="language-xml">              <span class="tag">&lt;<span class="name">th</span> <span class="attr">key</span>=<span class="string">&#123;i&#125;</span>&gt;</span>&#123;e.title&#125;<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            )&#125;</span></span><br><span class="line"><span class="language-xml">            <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;/<span class="name">thead</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;<span class="name">tbody</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            &#123;tbody.map((tr:any,a:any)=&gt;</span></span><br><span class="line"><span class="language-xml">              <span class="tag">&lt;<span class="name">tr</span> <span class="attr">key</span>=<span class="string">&#123;a&#125;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">              &#123;thead.map((td:any,b:any)=&gt;&#123;</span></span><br><span class="line"><span class="language-xml">                if(td.render)&#123;</span></span><br><span class="line"><span class="language-xml">                  return <span class="tag">&lt;<span class="name">td</span> <span class="attr">key</span>=<span class="string">&#123;b&#125;</span>&gt;</span>&#123;td.render(tr)&#125;<span class="tag">&lt;/<span class="name">td</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">                &#125;else&#123;</span></span><br><span class="line"><span class="language-xml">                  return <span class="tag">&lt;<span class="name">td</span> <span class="attr">key</span>=<span class="string">&#123;b&#125;</span>&gt;</span>&#123;td.title&#125;<span class="tag">&lt;/<span class="name">td</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">                &#125;</span></span><br><span class="line"><span class="language-xml">              &#125;)&#125;</span></span><br><span class="line"><span class="language-xml">              <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">            )&#125;</span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;/<span class="name">tbody</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;/<span class="name">table</span>&gt;</span>:</span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">className</span>=<span class="string">&quot;l_nodata&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">          <span class="tag">&lt;<span class="name">span</span>&gt;</span>No Date<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        &#125;</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">    )</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.l_table</span>&#123;<span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#c3c3c3</span>;<span class="attribute">background</span>: <span class="number">#fff</span>;<span class="attribute">margin-bottom</span>:<span class="number">20px</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-tag">table</span>&#123;<span class="attribute">width</span>:<span class="number">100%</span>&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-tag">th</span>,<span class="selector-class">.l_table</span> <span class="selector-tag">td</span>&#123;<span class="attribute">word-break</span>:keep-all;<span class="attribute">overflow</span>:hidden;<span class="attribute">white-space</span>:nowrap;-o-<span class="attribute">text-overflow</span>:ellipsis;<span class="attribute">text-overflow</span>:ellipsis;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-tag">table</span>,<span class="selector-class">.l_table</span> <span class="selector-tag">th</span>,<span class="selector-class">.l_table</span> <span class="selector-tag">td</span>&#123;<span class="attribute">border</span>:<span class="number">0</span>;<span class="attribute">border-spacing</span>:<span class="number">0</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-tag">td</span>&#123;<span class="attribute">padding</span>: <span class="number">6px</span> <span class="number">10px</span>;<span class="attribute">max-width</span>: <span class="number">150px</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_table_title</span>&#123;<span class="attribute">text-align</span>:center;<span class="attribute">font-weight</span>:<span class="number">700</span>;<span class="attribute">margin</span>:<span class="number">0</span>;<span class="attribute">padding</span>:<span class="number">16px</span> <span class="number">0</span>;<span class="attribute">position</span>:relative;<span class="attribute">top</span>:<span class="number">1px</span>;<span class="attribute">font-size</span>:<span class="number">14px</span>;<span class="attribute">color</span>:<span class="built_in">rgba</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0.65</span>);<span class="attribute">padding-right</span>:<span class="number">17px</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_scroll_hide</span>::-webkit-scrollbar&#123;<span class="attribute">background</span>:transparent&#125;</span><br><span class="line"><span class="selector-class">.l_scroll_hide</span>&#123;<span class="attribute">scrollbar-color</span>: transparent transparent;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-tag">th</span>&#123;<span class="attribute">background</span>:<span class="number">#fafafa</span>;<span class="attribute">position</span>:relative;<span class="attribute">z-index</span>:<span class="number">1</span>;<span class="attribute">box-sizing</span>:border-box;<span class="attribute">padding</span>:<span class="number">0px</span> <span class="number">10px</span>;<span class="attribute">text-align</span><span class="selector-pseudo">:left</span>&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-class">.l_table_head</span>&#123;<span class="attribute">border-top</span>:<span class="number">1px</span> solid <span class="number">#e8e8e8</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-class">.l_table_body</span> <span class="selector-tag">td</span>,<span class="selector-class">.l_table_head</span> <span class="selector-tag">th</span>,<span class="selector-class">.l_table</span> <span class="selector-class">.l_table_body</span> <span class="selector-tag">th</span>&#123;<span class="attribute">border-right</span>: <span class="number">1px</span> solid <span class="number">#e8e8e8</span>;<span class="attribute">border-bottom</span>: <span class="number">1px</span> solid <span class="number">#e8e8e8</span>&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-class">.l_table_head</span>&#123;<span class="attribute">overflow-x</span>:hidden;<span class="attribute">overflow-y</span>:scroll;&#125;</span><br><span class="line"><span class="selector-class">.l_table</span> <span class="selector-class">.l_table_body</span>&#123;<span class="attribute">overflow-y</span>:scroll;<span class="attribute">margin-top</span>: -<span class="number">35px</span>;&#125;</span><br><span class="line"><span class="selector-class">.l_table_head</span>,<span class="selector-class">.l_table_body</span> <span class="selector-tag">thead</span>&#123;<span class="attribute">line-height</span>:<span class="number">34px</span>&#125;</span><br><span class="line"><span class="selector-class">.l_table_body</span> <span class="selector-tag">thead</span>&#123;<span class="attribute">visibility</span>:hidden;&#125;</span><br><span class="line"><span class="selector-class">.l_nodata</span>&#123;<span class="attribute">position</span>:relative;<span class="attribute">height</span>:<span class="number">100%</span>&#125;</span><br><span class="line"><span class="selector-class">.l_nodata</span> <span class="selector-tag">span</span>&#123;<span class="attribute">position</span>:absolute;<span class="attribute">top</span>:<span class="built_in">calc</span>(<span class="number">50%</span> + <span class="number">10px</span>);<span class="attribute">left</span>:<span class="number">50%</span>;<span class="attribute">transform</span>:<span class="built_in">translate</span>(-<span class="number">25%</span>);&#125;</span><br></pre></td></tr></table></figure>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E6%89%93%E5%8D%B0%E5%8F%8A4A%E5%A4%A7%E5%B0%8F%E7%9A%84%E8%AE%BE%E7%BD%AE"><span class="toc-text">页面打印及4A大小的设置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%8B%E6%9C%BA%E5%92%8C%E7%94%B5%E8%84%91%E9%95%BF%E6%8C%89%E7%9A%84%E6%B7%B7%E5%90%88%E5%A4%84%E7%90%86"><span class="toc-text">手机和电脑长按的混合处理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E8%A1%A8%E6%A0%BC%E5%92%8C%E5%9B%BA%E5%AE%9A%E5%A4%B4%E9%83%A8%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="toc-text">数据表格和固定头部的样式</span></a></li></ol>
  </div>
</aside>

  
  
    <aside class="passage-copyright">
      <div>本文作者: 饿包子</div>
      
        <div>
          原文链接: 
          <a href="" target="_blank">https://lixianbin1.github.io/blog/2022/02/11/%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%A0%B7%E5%BC%8F%E7%9A%84%E5%8F%82%E8%80%83%E5%92%8C%E6%B2%89%E6%B7%80%E4%BB%A3%E7%A0%81/</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/blog/tags/Javascript/"><i class="fa fa-tags"></i>Javascript</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    
<div class="site-footer-wrapper">
<!--
  <div class="footer-top">
    <a class="left" href="/blog/2022/02/17/%E5%B7%A5%E5%85%B7%E6%8E%A8%E8%8D%90-sublime%E7%9A%84%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a class="right" href="/blog/2022/01/26/%E3%80%90%E6%B8%B8%E6%88%8F%E6%94%BB%E7%95%A5%E3%80%91%E8%A7%85%E9%95%BF%E7%94%9F/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
-->
  <footer class="site-footer">
    
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">网站推荐</h5>
          
            <span class="site-footer-item">
              <a href="https://tympanus.net/codrops/" target="_blank">Codrops</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://taobaofed.org/" target="_blank">淘宝前端团队(FED)</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">文档教程</h5>
          
            <span class="site-footer-item">
              <a href="https://es6.ruanyifeng.com/" target="_blank">ES6入门</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://developer.mozilla.org/zh-CN/docs/Web" target="_blank">MDN Web文档</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">兴趣前沿</h5>
          
            <span class="site-footer-item">
              <a href="https://threejs.org/" target="_blank">threejs</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://github.com/justadudewhohacks/face-api.js" target="_blank">face-api</a>
            </span>
          
        </div>
      
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: xianbin.me@qq.com
      </div>
    
<!--     <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div> -->
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
        <div class="site-layer-reward" id="site-layer-reward" style="display: none;">
          
            <div>
              <img src="/blog/images/wechat.png" alt="WeChat">
              
                <p>WeChat</p>
              
            </div>
          
            <div>
              <img src="/blog/images/alipay.png" alt="AliPay">
              
                <p>AliPay</p>
              
            </div>
          
        </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">

  <div class="bottom-bar-left">
<!--
    <a href="/blog/2022/02/17/%E5%B7%A5%E5%85%B7%E6%8E%A8%E8%8D%90-sublime%E7%9A%84%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/blog/2022/01/26/%E3%80%90%E6%B8%B8%E6%88%8F%E6%94%BB%E7%95%A5%E3%80%91%E8%A7%85%E9%95%BF%E7%94%9F/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
-->
  </div>

  
  
  
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
    <a id="share-btn-weibo" href="javascript:void(0);" target="_blank">
      <i class="fa fa-weibo"></i>
    </a>
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
</div>
    





    
  </body>
</html>